package no.saiboten.tourbuilder.login;

import javax.servlet.http.HttpServletRequest;

import no.saiboten.tourbuilder.user.User;
import no.saiboten.tourbuilder.user.UserDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LoginServiceImpl implements LoginService {

	@Autowired
	HttpServletRequest request;

	@Autowired
	UserDAO userDAO;

	@Override
	public User login(String userName, String password) {
		User user = userDAO.getUser(userName);
		if (user != null) {
			if (password.equals(user.getPassword())) {
				request.getSession().setAttribute("user", user);
				return user;
			}
		}
		return null;
	}

}
